package cate.game.play.skill.passive.god;

import cate.common.table.d.GD;
import cate.game.attr.FightAttr;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 攻击额外对至多1个目标造成0.12*（1*自身pk加伤+0.2*自身伤害减免）*自身当前生命值的伤害,不超过目标最大生命值的20%，冷却1回合
 */
public class 攻之转化PH extends PassiveHandler {

	private double 系数;
	private double 加伤系数;
	private double 减伤系数;
	private double 最大系数;

	//系数=1200&加伤系数=10000&减伤系数=2000&最大系数=2000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		系数 = args.getWDouble("系数", 0d);
		加伤系数 = args.getWDouble("加伤系数", 0d);
		减伤系数 = args.getWDouble("减伤系数", 0d);
		最大系数 = args.getWDouble("最大系数", 0d);
	}

	private int lastRound;

	@Override
	public void onSkillDone(SkillActionCtx action) {
		if (lastRound >= action.getRound().index) {
			return;
		}
		if (!action.getSkill().cfg.isHurtSkill()) {
			return;
		}
		FightAttr total = skill.owner.attr.total();
		double damage = 系数 * (加伤系数 * total.pvpUp() + 减伤系数 * total.hurtIgn()) / GD.W_10000_0 * total.hpCur();
		Fighter target = TargetSelector.findOne(skill.owner, action.getTeamVs(), new TargetFilterParam());
		if (target != null) {
			double max = target.attr.total().hpTotal() * 最大系数;
			damage = Math.min(damage, max);
			target.attr.passiveHurt(action, skill.owner, damage);
		}
		lastRound = action.getRound().index;
	}
}
